package com.geostar.constructionland.attachment.service;

import com.geostar.constructionland.attachment.util.AppUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author : yell
 * @Description: 存储服务工厂
 * @date : 2021/01/07 9:49
 */
@Component
public class StorageServiceFactory {
    @Value("${storageType:fastDFSStorageService}")
    String storageType;
    private AppUtil appUtil;
    @Autowired
    public void setAppUtil(AppUtil appUtil) {
        this.appUtil = appUtil;
    }

    /***
     * 获取当前配置的附件存储服务
     * @return
     */
    public IStorageService getCurrentService(){
        return appUtil.getBean(storageType);
    }

    public IStorageService getStorageService(String serviceName) throws Exception{
        IStorageService storageService = appUtil.getBean(serviceName);
        if(storageService==null){
            throw new Exception("服务ID:"+serviceName+"未注册，或者未实现");
        }
        return storageService;
    }
}
